﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Globalization;
using Public;

namespace WebsiteAdmin.Salomon.ProInfo
{
    public partial class ProCreate : System.Web.UI.Page
    {
        public DataTable dtRtn = new DataTable();

        
        protected void Page_Load(object sender, EventArgs e)
        {
            GetCatList();
        }

        protected void GetCatList()
        {
            DataTable dt = Bll.Category.MULTIPLE(Global.ConSalomon);
            if (dt.Rows.Count > 0)
            {

                // Add three column objects to the table.
                DataColumn dc1 = new DataColumn();
                dc1.DataType = System.Type.GetType("System.Int32");
                dc1.ColumnName = "PKID";
                //dc1.AutoIncrement = true;
                dtRtn.Columns.Add(dc1);

                DataColumn dc2 = new DataColumn();
                dc2.DataType = System.Type.GetType("System.String");
                dc2.ColumnName = "CatName";
                //dc2.AutoIncrement = true;
                dtRtn.Columns.Add(dc2);

                DataColumn dc3 = new DataColumn();
                dc3.DataType = System.Type.GetType("System.Int32");
                dc3.ColumnName = "ParID";
                //dc3.AutoIncrement = true;
                dtRtn.Columns.Add(dc3);

                DataColumn dc4 = new DataColumn();
                dc4.DataType = System.Type.GetType("System.Int32");
                dc4.ColumnName = "CatRank";
                //dc4.AutoIncrement = true;
                dtRtn.Columns.Add(dc4);

                DataColumn dc5 = new DataColumn();
                dc5.DataType = System.Type.GetType("System.Int32");
                dc5.ColumnName = "SortBy";
                //dc5.AutoIncrement = true;
                dtRtn.Columns.Add(dc5);

                DataColumn dc6 = new DataColumn();
                dc6.DataType = System.Type.GetType("System.Int32");
                dc6.ColumnName = "Num";
                //dc5.AutoIncrement = true;
                dtRtn.Columns.Add(dc6);


                GetCatData(0, dt, dtRtn);

                if (dtRtn.Rows.Count > 0)
                {
                    RP_Category.DataSource = dtRtn.DefaultView;
                    RP_Category.DataBind();
                }

            }
        }

        protected void GetCatData(int parID, DataTable dtCat, DataTable dtRtn)
        {
            DataRow[] drs = dtCat.Select(" [ParID] = " + parID);

            for (int i = 0; i < drs.Length; i++)
            {
                DataRow dr = dtRtn.NewRow();
                dr["PKID"] = Convert.ToInt32(drs[i]["PKID"]);
                dr["CatName"] = drs[i]["CatName"].ToString();
                dr["ParID"] = Convert.ToInt32(drs[i]["ParID"]);
                dr["CatRank"] = Convert.ToInt32(drs[i]["CatRank"]);
                dr["SortBy"] = Convert.ToInt32(drs[i]["SortBy"]);
                dr["Num"] = Convert.ToInt32(drs[i]["Num"]);
                dtRtn.Rows.Add(dr);
                GetCatData(Convert.ToInt32(drs[i]["PKID"]), dtCat, dtRtn);
            }
        }

        protected void RP_Category_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                // 找到分类Repeater关联的数据项
                DataRowView rowv = (DataRowView)e.Item.DataItem;

                Label lblCatSelect = ((Label)e.Item.FindControl("CatSelect"));
                string tmp = rowv["CatName"].ToString();
                if (Convert.ToInt32(rowv["CatRank"]) == 1)
                {
                    if ((Convert.ToInt32(rowv["Num"]) == 0))
                        lblCatSelect.Text = "<h4><a href=\"javascript:void(0);\" onclick=\"javascript:CatSelect(" + Convert.ToInt32(rowv["PKID"]) + ",'" + tmp + "');\">" + tmp + "</a></h4>";
                    else
                        lblCatSelect.Text = "<h4>" + tmp + "</h4>";

                }
                else if (Convert.ToInt32(rowv["CatRank"]) == 2)
                {
                    if ((Convert.ToInt32(rowv["Num"]) == 0))
                        lblCatSelect.Text = "<b><a href=\"javascript:void(0);\" onclick=\"javascript:CatSelect(" + Convert.ToInt32(rowv["PKID"]) + ",'" + tmp + "');\">" + tmp + "</a></b>";
                    else
                        lblCatSelect.Text = "<b>" + tmp + "</b>";
                }
                else
                {
                    if ((Convert.ToInt32(rowv["Num"]) == 0))
                        lblCatSelect.Text = "<a href=\"javascript:void(0);\" onclick=\"javascript:CatSelect(" + Convert.ToInt32(rowv["PKID"]) + ",'" + tmp + "');\">" + tmp + "</a>";
                    else
                        lblCatSelect.Text = "" + tmp + "";
                }



            }
        }

    }

}
